import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;

public class TransientTest {
    public static void main(String[] args){
        User user=new User();
        user.setName("小马哥");
        user.setPassword("123123");
        System.out.println("Serializable之前：");
        System.out.println("user namr:"+user.getName());
        System.out.println("user password:"+user.getPassword());

        try {
            ObjectOutputStream oop=new ObjectOutputStream(new FileOutputStream(("C:/user.txt")));
            oop.writeObject(user);
            oop.flush();
            oop.close();
        } catch (Exception e) {
            e.printStackTrace();
        }

        try {
            ObjectInputStream ois=new ObjectInputStream(new FileInputStream("C:/user.txt"));
            User rUser=(User)ois.readObject();
            ois.close();
            System.out.println("Serializable之后：");
            System.out.println("user namr:"+rUser.getName());
            System.out.println("user password:"+rUser.getPassword());

        } catch (Exception e) {
            e.printStackTrace();
        }


    }
}
